//
// Created by 下次一定 on 2021/9/7.
//kmp算法
//p[1,j] == p[i-j+1,i]

#include <iostream>

using namespace std;

const int N = 10010, M = 10010;

// n 是长的模式串
int n, m;
char p[N], s[M];
int ne[N];

int main() {
    cin >> n >> p + 1 >> m >> s + 1;


    // 求next的过程
    for (int i = 2, j = 0; i <= n; i++) {
        while (j && p[i] != p[j + 1]) j = ne[j];
        if (p[i] == p[j + 1]) j++;
        ne[i] = j;
    }


    //kmp匹配过程
    for (int i = 1, j = 0; i <= m; i++) {
        while (j && s[i != p[j + 1]]) j = ne[j];
        if (s[i] == p[j + 1]) j++;
        if (j == n) {
            //匹配成功
            cout<< i-n;
            j = ne[j];
        }
    }
}

